////////////////////////////////////////////////////////////////////////////////
//
//  The MIT License
//
//  Copyright (c) 2008 - 2009. Dimarik
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//
////////////////////////////////////////////////////////////////////////////////

package ru.goodcore.transport
{

import flash.events.Event;

import ru.goodcore.core.QueryLink;
import ru.goodcore.errors.GenericError;
import ru.goodcore.errors.GenericErrorCode;
import ru.goodcore.logging.ILogger;
import ru.goodcore.logging.Log;
import ru.goodcore.net.URI;

/**
 *  @author				Dimarik
 *  @version			1.0
 *  @langversion		3.0
 *  @playerversion		9.0
 *
 */
public class AbstractTransport extends QueryLink {

	//-------------------------------------------------------------------------
	//
	//   Constructor
	//
	//-------------------------------------------------------------------------

	public function AbstractTransport() {
		super();

		if ( (this as Object).constructor === AbstractTransport)
			throw new GenericError(GenericErrorCode.CLASS_CANNOT_BE_INSTANTIATED);
	}

	//-------------------------------------------------------------------------
	//
	//   Properties
	//
	//-------------------------------------------------------------------------

	//---------------------------------
	//  connected
	//---------------------------------
	/**
	 * @private
	 */
	private var _connected:	Boolean = false;

	public function get connected():Boolean {
		return this._connected;
	}

	public function set connected(value:Boolean):void {
		if (this._connected == value) return;
		this._connected = value;
	}

	//---------------------------------
	//  data
	//---------------------------------
	/**
	 * @private
	 */
	private var _data:	*;

	public function get data():* {
		return this._data;
	}

	public function set data(value:*):void {
		if (this._data == value) return;
		this._data = value;
	}

	//---------------------------------
	//  logger
	//---------------------------------
	/**
	 * @private
	 */
	protected var $logger:	ILogger;

	public function get logger():ILogger {
		if ( !this.$logger ) {
			this.$logger = Log.getLogger(this);
		}
		return this.$logger;
	}

	//-------------------------------------------------------------------------
	//
	//   Overriden methods: EventDispatcher
	//
	//-------------------------------------------------------------------------

	/**
	 * @private 
	 * @param event
	 * @return 
	 */
	public override function dispatchEvent(event:Event):Boolean {
		if ( super.hasEventListener(event.type) )
			return super.dispatchEvent(event);

		return false;
	}

	//-------------------------------------------------------------------------
	//
	//   Public methods
	//
	//-------------------------------------------------------------------------

	public virtual function connect(uri:URI):void {
		throw new GenericError(GenericErrorCode.METHOD_MUST_BE_OVERRIDDEN);
	}

	public virtual function send(options:Object = null):void {
		throw new GenericError(GenericErrorCode.METHOD_MUST_BE_OVERRIDDEN);
	}

	public virtual function close():void {
		throw new GenericError(GenericErrorCode.METHOD_MUST_BE_OVERRIDDEN);
	}

}
}